<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
	public function _initResource() {
		Zend_Registry::set('Db', Zend_Db::factory(new Zend_Config(require APPLICATION_PATH . '/configs/db.php')));
		Zend_Registry::set('Zend_Locale', new Zend_Locale('vi_VN'));
		//Zend_Date::setOptions();
		Zend_Session::start();
		$Session = new Zend_Session_Namespace('Admin', TRUE);
		$Session->setExpirationSeconds(600);
		Zend_Registry::set('Session', $Session);
		Zend_View_Helper_PaginationControl::setDefaultViewPartial('_pagination.phtml');
	}
	
	public function _initAutoload() {
		$autoLoaderResource = new Zend_Loader_Autoloader_Resource(
                            array(
                                'basePath' => APPLICATION_PATH ,
                                'namespace' => 'Admin'
                            )
                        );
		
		$autoLoaderResource->addResourceType('model', 'models/', 'Model');
		
		return $autoLoaderResource;
	}
	
	public function _initOther() {
		$this->bootstrap('view');
		$view = $this->getResource('view');
		$Resources = $this->getOption('resources');
		$view->getHelper('BaseUrl')->setBaseUrl($Resources['frontController']['baseUrl']);
		
		$MetaKeys = require APPLICATION_PATH . '/configs/head.php';
		foreach ($MetaKeys['meta'] as $Key => $Value) {
			if (is_array($Value)) {
				$Value = implode(',', $Value);
			}
			
			$view->headMeta()->appendName($Key, $Value);
		}
		
		foreach ($MetaKeys['link'] as $Key => $Value) {
			if (is_array($Value)) {
				$Value = implode(',', $Value);
			}
			
			$view->headLink()->appendStylesheet($view->baseUrl($Value));
		}
		
		//$MetaKeys = require APPLICATION_PATH . '/configs/head.meta.php';
		foreach ($MetaKeys['script'] as $Key => $Value) {
			if (is_array($Value)) {
				$Value = implode(',', $Value);
			}
			
			$view->headScript()->appendFile($view->baseUrl($Value));
		}
		
		
		//ZendX_JQuery::enableView($view);
		//$view->addHelperPath('ZendX/JQuery/View/Helper/', 'ZendX_JQuery_View_Helper');
		
		$view->assign('AdminMenu', new Zend_Navigation(require APPLICATION_PATH . '/configs/menu.php'));
	}
	
	public function _initAuthorize() {
		Zend_Registry::set('Admin', TRUE);
	}
}

